import requests
# 定义一个全局变量
sess = requests.session()
ip = "192.168.1.59"
rp = sess.request("get",url="http://www.baidu.com")
# 发送http请求，并接受
# rp = my_requests.get(url="http://www.baidu.com")
# print(type(rp.text))
# print(rp.text)
def gettest():
    # get请求参数 存入params变量
    params = {"id":1}
    rp = sess.request("get",url="http://"+ ip +":8080/pinter/com/getSku",params= params)
    print(rp.text)
def posttest():
    # post请求，使用data进行传参
    data = {"userName":"admin","password":"123456"}
    rp = sess.request("port", url="http://192.168.1.59:8080/pinter/com/login", data=data)
    print(rp.text)
def post_json_test():
    # 传json参数，使用json变量进行传参
    json = {"userName":"test","password":"1234","gender":1,"phoneNum":"110","email":"beihe@163.com","address":"Beijing"}
    rp = sess.request("port", url="http://192.168.1.59:8080/pinter/com/login", json=json)
    print(rp.text)
# 参数为 k=json的post接口
def key_json_posttes():
    # post请求，使用data进行传参
    data = {"userName": "admin", "password": "123456"}
    rp = sess.request("port", url="http://"+ip+":8080/pinter/com/buy", data=data)
    print(rp.text)
# 返回json数据的get接口
def get_values_test():
    # get请求参数 存入params变量
    params = {"genderType":0}
    rp = sess.request("get",url="http://"+ip+":8080/pinter/com/userList",params= params)
    print(rp.text)

if __name__ == '__main__':
    gettest()
    posttest()
    post_json_test()
    key_json_posttes()
    get_values_test()